<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>权限</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../bangnuo/admin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../bangnuo/admin/style/admin.css" media="all">
</head>

<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label"></label>
                    <input type="hidden" id="id" name="id" placeholder="" autocomplete="off" class="layui-input">
                    <div class="layui-input-block" id="menuName">
                    </div>
                    <br/><br/>
                    <div class="layui-form-item">
                        <div class="layui-btn-container" style="padding-bottom: 10px; margin-left: 110px; margin-right: -110px;">
                            <button class="layui-btn" lay-submit lay-filter="role-form" data-type="close">立即提交</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="../../../bangnuo/admin/layui/layui.js"></script>
<script type="text/javascript" src="../../../bangnuo/admin/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript">

       layui.use(['form', 'upload', 'layer'], function () {
        var form = layui.form;
        var resultData;
        var htmls = ''; //全局变量
        //检查项目添加到下拉框中
        $.ajax({
            url: '/permissionsEntity/menuList',
            dataType: 'json',
            type: 'get',
            success: function (data) {
                resultData = data.queryResult.list;
                for (var x in resultData) {
                    htmls += '<input class="bt" type="checkbox" value="' + resultData[x].id + '"  name = "' + resultData[x].id + '">' + resultData[x].menuName + '</input></br>';
                }
                $("#menuName").html(htmls);
                form.render('checkbox');
                se();
                //重新渲染 固定写法
            }
        })
    });

</script>
<!--获取id回显数据-->
<script type="text/javascript">

    function se() {
        var form;
        layui.use(['form', 'layer'], function () {
            var $ = layui.$;
            form = layui.form;
        });
        //获取地址栏路径
        var url = window.location.href;
        //获取“=”的下标
        var pos = url.indexOf("=");
        //获取“=”后的全部字符（用户id）
        var id = url.substring(pos + 1, url.length);
        $.ajax({
            url: "/permissionsEntity/selectMenu/" + id,
            contentType: "application/json;charset=UTF-8",
            type: "get",
            success: function (data) {
                //给公司类型赋值并设置默认选中
                var unitType = [];
                debugger;
                unitType = data.queryResult.list;
                for (var j = 0; j < unitType.length; j++) {
                    var unitTypeCheckbox = $(".bt");
                    for (var i = 0; i < unitTypeCheckbox.length; i++) {
                        if (unitTypeCheckbox[i].name == unitType[j].id) {
                            unitTypeCheckbox[i].value = unitType[j].id;
                            unitTypeCheckbox[i].checked = true;
                        }
                    }
                    form.render('checkbox');  //更新渲染
                }
                ;
                $("#id").val(id);
            },
            complete: function (XMLHttpRequest, textStatus) {
            },
            ifModified: false,
            error: function () {
            }
        });
    }
</script>
<!--执行修改-->
<script type="text/javascript">
    layui.use(['form', 'layer'], function () {
        var $ = layui.$,
            form = layui.form,
            layer = layui.layer,
            index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        //监听提交
        form.on('submit(role-form)', function (data) {
            $.ajax({
                type: "post",
                contentType: "application/json;charset=UTF-8",
                url: "/permissionsEntity/edit",
                async: true,
                data: JSON.stringify(data.field),
                success: function (data) {
                    if (data.success == true) {
                        layer.msg(data.message);
                        $(document).ready(function () {
                            var  index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            console.log("index值",index);
                            close();
                        });
                    } else {
                        layer.msg(data.message);
                    }
                }
            });
            return false;
        });

    });
</script>
</body>
</html>